package bhbt.service.log;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import bhbt.model.Member;
import bhbt.model.log.LogStore;
import bhbt.model.log.LogStorePay;
import bhbt.service.MemberService;
import bhbt.service.core.BaseService;






@Service
public class LogStorePayService extends BaseService {
	
	@Resource
    private LogStorePayService logStorePayService;
	@Resource
    private MemberService memberService;
	@Resource
    private LogStoreService logStoreService;
	
	public void savePay(LogStorePay logStorePay){
		logStorePayService.saveOrUpdate(logStorePay);
		
		Double num = logStorePay.getNum();
		
		/**********************业务操作***************************/
		
		//转账会员
		Integer fromMemberId = logStorePay.getFromMemberId();
		Member fromMember =memberService.getByKey(fromMemberId);
		
		//接收会员
		Integer toMemberId = logStorePay.getToMemberId();
		Member toMember =memberService.getByKey(toMemberId);
		
		//转账会员操作
		Map<String, Object> mapMember = new HashMap<String, Object>();
		mapMember.put("id",fromMemberId);
		mapMember.put("diyUpdate","Store=Store-"+num);
        //更新余额 
        memberService.update(mapMember);
        
        fromMember= memberService.getByKey(fromMember.getId());
        Double fromYu = fromMember.getStore();
        
        
        //日志
        LogStore logStoreFrom = new LogStore();
        logStoreFrom.setMemberId(fromMember.getId());
        logStoreFrom.setTitle("转账，接收会员："+toMember.getLoginName());
        logStoreFrom.setState(88);
       
        logStoreFrom.setNum(-num);
        logStoreFrom.setYu(fromYu);
       
        logStoreService.saveOrUpdate(logStoreFrom);
        
        //接收会员操作
        mapMember = new HashMap();
        mapMember.put("id",toMemberId);
        mapMember.put("diyUpdate","Store=Store+"+num);
        //更新余额 
        memberService.update(mapMember);
         

        toMember= memberService.getByKey(toMember.getId());
        Double toYu = toMember.getStore();
        
        //日志
        LogStore logStoreTo = new LogStore();
        logStoreTo.setMemberId(toMember.getId());
        logStoreTo.setTitle("转账，转账会员："+fromMember.getLoginName());
        logStoreTo.setState(88);
        logStoreTo.setNum(num);
        logStoreTo.setYu(toYu);
       
        logStoreService.saveOrUpdate(logStoreTo);
        
         
		
	}

}
